home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / java / util / Date.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  5.7 KB  |  434 lines

  1. package java.util;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5. import java.io.ObjectOutputStream;
  6. import java.io.Serializable;
  7. import java.text.DateFormat;
  8. import java.text.SimpleDateFormat;
  9.  
  10. public class Date implements Serializable, Cloneable {
  11.    private transient Calendar cal;
  12.    private transient long fastTime;
  13.    private transient boolean modified;
  14.    private static final long serialVersionUID = 7523967970034938905L;
  15.    private static final String[] wtb = new String[]{"am", "pm", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday", "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december", "gmt", "ut", "utc", "est", "edt", "cst", "cdt", "mst", "mdt", "pst", "pdt"};
  16.    private static final int[] ttb = new int[]{14, 1, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 10000, 10000, 10000, 10300, 10240, 10360, 10300, 10420, 10360, 10480, 10420};
  17.  
  18.    public Date() {
  19.       this(System.currentTimeMillis());
  20.    }
  21.  
  22.    public Date(long var1) {
  23.       this.cal = null;
  24.       this.fastTime = var1;
  25.       this.modified = false;
  26.    }
  27.  
  28.    public Date(int var1, int var2, int var3) {
  29.       this(var1, var2, var3, 0, 0, 0);
  30.    }
  31.  
  32.    public Date(int var1, int var2, int var3, int var4, int var5) {
  33.       this(var1, var2, var3, var4, var5, 0);
  34.    }
  35.  
  36.    public Date(int var1, int var2, int var3, int var4, int var5, int var6) {
  37.       this.cal = new GregorianCalendar(var1 + 1900, var2, var3, var4, var5, var6);
  38.       this.cal.complete();
  39.       this.modified = false;
  40.    }
  41.  
  42.    public Date(String var1) {
  43.       this(parse(var1));
  44.    }
  45.  
  46.    public static long UTC(int var0, int var1, int var2, int var3, int var4, int var5) {
  47.       GregorianCalendar var6 = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
  48.       ((Calendar)var6).set(1, var0 + 1900);
  49.       ((Calendar)var6).set(2, var1);
  50.       ((Calendar)var6).set(5, var2);
  51.       ((Calendar)var6).set(11, var3);
  52.       ((Calendar)var6).set(12, var4);
  53.       ((Calendar)var6).set(13, var5);
  54.       return ((Calendar)var6).getTimeInMillis();
  55.    }
  56.  
  57.    public static long parse(String var0) {
  58.       int var1 = -1;
  59.       byte var2 = -1;
  60.       byte var3 = -1;
  61.       int var4 = -1;
  62.       byte var5 = -1;
  63.       byte var6 = -1;
  64.       char var7 = '\uffff';
  65.       int var8 = 0;
  66.       int var9 = -1;
  67.       int var10 = -1;
  68.       char var11 = 0;
  69.       if (var0 != null) {
  70.          int var12 = var0.length();
  71.  
  72.          while(true) {
  73.             if (var8 >= var12) {
  74.                if (var1 >= 0 && var2 >= 0 && var3 >= 0) {
  75.                   if (var6 < 0) {
  76.                      var6 = 0;
  77.                   }
  78.  
  79.                   if (var5 < 0) {
  80.                      var5 = 0;
  81.                   }
  82.  
  83.                   if (var4 < 0) {
  84.                      var4 = 0;
  85.                   }
  86.  
  87.                   if (var10 == -1) {
  88.                      return (new Date(var1, var2, var3, var4, var5, var6)).getTime();
  89.                   }
  90.  
  91.                   return UTC(var1, var2, var3, var4, var5, var6) + (long)(var10 * '\uea60');
  92.                }
  93.                break;
  94.             }
  95.  
  96.             var7 = var0.charAt(var8);
  97.             ++var8;
  98.             if (var7 > ' ' && var7 != ',') {
  99.                if (var7 == '(') {
  100.                   int var21 = 1;
  101.  
  102.                   while(var8 < var12) {
  103.                      var7 = var0.charAt(var8);
  104.                      ++var8;
  105.                      if (var7 == '(') {
  106.                         ++var21;
  107.                      } else if (var7 == ')') {
  108.                         --var21;
  109.                         if (var21 <= 0) {
  110.                            break;
  111.                         }
  112.                      }
  113.                   }
  114.                } else if (var7 >= '0' && var7 <= '9') {
  115.                   for(var9 = var7 - 48; var8 < var12 && (var7 = var0.charAt(var8)) >= '0' && var7 <= '9'; ++var8) {
  116.                      var9 = var9 * 10 + var7 - 48;
  117.                   }
  118.  
  119.                   if (var11 != '+' && (var11 != '-' || var1 < 0)) {
  120.                      if (var9 >= 70) {
  121.                         if (var1 >= 0 || var7 > ' ' && var7 != ',' && var7 != '/' && var8 < var12) {
  122.                            break;
  123.                         }
  124.  
  125.                         var1 = var9 < 1900 ? var9 : var9 - 1900;
  126.                      } else if (var7 == ':') {
  127.                         if (var4 < 0) {
  128.                            var4 = (byte)var9;
  129.                         } else {
  130.                            if (var5 >= 0) {
  131.                               break;
  132.                            }
  133.  
  134.                            var5 = (byte)var9;
  135.                         }
  136.                      } else if (var7 == '/') {
  137.                         if (var2 < 0) {
  138.                            var2 = (byte)(var9 - 1);
  139.                         } else {
  140.                            if (var3 >= 0) {
  141.                               break;
  142.                            }
  143.  
  144.                            var3 = (byte)var9;
  145.                         }
  146.                      } else {
  147.                         if (var8 < var12 && var7 != ',' && var7 > ' ' && var7 != '-') {
  148.                            break;
  149.                         }
  150.  
  151.                         if (var4 >= 0 && var5 < 0) {
  152.                            var5 = (byte)var9;
  153.                         } else if (var5 >= 0 && var6 < 0) {
  154.                            var6 = (byte)var9;
  155.                         } else {
  156.                            if (var3 >= 0) {
  157.                               break;
  158.                            }
  159.  
  160.                            var3 = (byte)var9;
  161.                         }
  162.                      }
  163.                   } else {
  164.                      if (var9 < 24) {
  165.                         var9 *= 60;
  166.                      } else {
  167.                         var9 = var9 % 100 + var9 / 100 * 60;
  168.                      }
  169.  
  170.                      if (var11 == '+') {
  171.                         var9 = -var9;
  172.                      }
  173.  
  174.                      if (var10 != 0 && var10 != -1) {
  175.                         break;
  176.                      }
  177.  
  178.                      var10 = var9;
  179.                   }
  180.  
  181.                   var11 = 0;
  182.                } else if (var7 != '/' && var7 != ':' && var7 != '+' && var7 != '-') {
  183.                   int var13;
  184.                   for(var13 = var8 - 1; var8 < var12; ++var8) {
  185.                      var7 = var0.charAt(var8);
  186.                      if ((var7 < 'A' || var7 > 'Z') && (var7 < 'a' || var7 > 'z')) {
  187.                         break;
  188.                      }
  189.                   }
  190.  
  191.                   if (var8 <= var13 + 1) {
  192.                      break;
  193.                   }
  194.  
  195.                   int var14 = wtb.length;
  196.  
  197.                   while(true) {
  198.                      --var14;
  199.                      if (var14 < 0) {
  200.                         break;
  201.                      }
  202.  
  203.                      if (wtb[var14].regionMatches(true, 0, var0, var13, var8 - var13)) {
  204.                         int var15 = ttb[var14];
  205.                         if (var15 != 0) {
  206.                            if (var15 == 1) {
  207.                               if (var4 > 12 || var4 < 1) {
  208.                                  throw new IllegalArgumentException();
  209.                               }
  210.  
  211.                               if (var4 < 12) {
  212.                                  var4 += 12;
  213.                               }
  214.                            } else if (var15 == 14) {
  215.                               if (var4 > 12 || var4 < 1) {
  216.                                  throw new IllegalArgumentException();
  217.                               }
  218.  
  219.                               if (var4 == 12) {
  220.                                  var4 = 0;
  221.                               }
  222.                            } else if (var15 <= 13) {
  223.                               if (var2 >= 0) {
  224.                                  throw new IllegalArgumentException();
  225.                               }
  226.  
  227.                               var2 = (byte)(var15 - 2);
  228.                            } else {
  229.                               var10 = var15 - 10000;
  230.                            }
  231.                         }
  232.                         break;
  233.                      }
  234.                   }
  235.  
  236.                   if (var14 < 0) {
  237.                      break;
  238.                   }
  239.  
  240.                   var11 = 0;
  241.                } else {
  242.                   var11 = var7;
  243.                }
  244.             }
  245.          }
  246.       }
  247.  
  248.       throw new IllegalArgumentException();
  249.    }
  250.  
  251.    public int getYear() {
  252.       this.checkCal();
  253.       this.checkModified();
  254.       return this.cal.get(1) - 1900;
  255.    }
  256.  
  257.    public void setYear(int var1) {
  258.       this.checkCal();
  259.       this.cal.clear(16);
  260.       this.cal.clear(15);
  261.       this.cal.set(1, var1 + 1900);
  262.       this.modified = true;
  263.    }
  264.  
  265.    public int getMonth() {
  266.       this.checkCal();
  267.       this.checkModified();
  268.       return this.cal.get(2);
  269.    }
  270.  
  271.    public void setMonth(int var1) {
  272.       this.checkCal();
  273.       this.cal.clear(16);
  274.       this.cal.clear(15);
  275.       this.cal.set(2, var1);
  276.       this.modified = true;
  277.    }
  278.  
  279.    public int getDate() {
  280.       this.checkCal();
  281.       this.checkModified();
  282.       return this.cal.get(5);
  283.    }
  284.  
  285.    public void setDate(int var1) {
  286.       this.checkCal();
  287.       this.cal.clear(16);
  288.       this.cal.clear(15);
  289.       this.cal.set(5, var1);
  290.       this.modified = true;
  291.    }
  292.  
  293.    public int getDay() {
  294.       this.checkCal();
  295.       this.checkModified();
  296.       return this.cal.get(7) - 1;
  297.    }
  298.  
  299.    public int getHours() {
  300.       this.checkCal();
  301.       this.checkModified();
  302.       return this.cal.get(11);
  303.    }
  304.  
  305.    public void setHours(int var1) {
  306.       this.checkCal();
  307.       this.cal.clear(16);
  308.       this.cal.clear(15);
  309.       this.cal.set(11, var1);
  310.       this.modified = true;
  311.    }
  312.  
  313.    public int getMinutes() {
  314.       this.checkCal();
  315.       this.checkModified();
  316.       return this.cal.get(12);
  317.    }
  318.  
  319.    public void setMinutes(int var1) {
  320.       this.checkCal();
  321.       this.cal.clear(16);
  322.       this.cal.clear(15);
  323.       this.cal.set(12, var1);
  324.       this.modified = true;
  325.    }
  326.  
  327.    public int getSeconds() {
  328.       this.checkCal();
  329.       this.checkModified();
  330.       return this.cal.get(13);
  331.    }
  332.  
  333.    public void setSeconds(int var1) {
  334.       this.checkCal();
  335.       this.cal.clear(16);
  336.       this.cal.clear(15);
  337.       this.cal.set(13, var1);
  338.       this.modified = true;
  339.    }
  340.  
  341.    public long getTime() {
  342.       if (this.cal == null) {
  343.          return this.fastTime;
  344.       } else {
  345.          this.checkModified();
  346.          return this.cal.getTimeInMillis();
  347.       }
  348.    }
  349.  
  350.    public void setTime(long var1) {
  351.       if (this.cal == null) {
  352.          this.fastTime = var1;
  353.          this.modified = false;
  354.       } else {
  355.          this.cal.setTimeInMillis(var1);
  356.          this.cal.computeFields();
  357.          this.modified = false;
  358.       }
  359.    }
  360.  
  361.    public boolean before(Date var1) {
  362.       return this.getTime() < var1.getTime();
  363.    }
  364.  
  365.    public boolean after(Date var1) {
  366.       return this.getTime() > var1.getTime();
  367.    }
  368.  
  369.    public boolean equals(Object var1) {
  370.       return var1 != null && var1 instanceof Date && this.getTime() == ((Date)var1).getTime();
  371.    }
  372.  
  373.    public int hashCode() {
  374.       long var1 = this.getTime();
  375.       return (int)var1 ^ (int)(var1 >> 32);
  376.    }
  377.  
  378.    public String toString() {
  379.       SimpleDateFormat var1 = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
  380.       ((DateFormat)var1).setTimeZone(TimeZone.getDefault());
  381.       return ((DateFormat)var1).format(this);
  382.    }
  383.  
  384.    public String toLocaleString() {
  385.       DateFormat var1 = DateFormat.getDateTimeInstance();
  386.       var1.setTimeZone(TimeZone.getDefault());
  387.       return var1.format(this);
  388.    }
  389.  
  390.    public String toGMTString() {
  391.       SimpleDateFormat var1 = new SimpleDateFormat("d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
  392.       ((DateFormat)var1).setTimeZone(TimeZone.getTimeZone("GMT"));
  393.       return ((DateFormat)var1).format(this);
  394.    }
  395.  
  396.    public int getTimezoneOffset() {
  397.       this.checkCal();
  398.       this.checkModified();
  399.       TimeZone var1 = this.cal.getTimeZone();
  400.       int var2 = var1.getOffset(this.cal.get(0), this.cal.get(1), this.cal.get(2), this.cal.get(5), this.cal.get(7), this.cal.get(11) * this.cal.get(12) * this.cal.get(13) * 1000);
  401.       return -(var2 / 1000 / 60);
  402.    }
  403.  
  404.    private void writeObject(ObjectOutputStream var1) throws IOException {
  405.       var1.writeLong(this.getTime());
  406.    }
  407.  
  408.    private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  409.       long var2 = var1.readLong();
  410.       this.cal = new GregorianCalendar(TimeZone.getDefault());
  411.       this.cal.setTimeInMillis(var2);
  412.       this.cal.computeFields();
  413.       this.modified = false;
  414.    }
  415.  
  416.    private void checkCal() {
  417.       if (this.cal == null) {
  418.          this.cal = new GregorianCalendar(TimeZone.getDefault());
  419.          this.cal.setTimeInMillis(this.fastTime);
  420.          this.cal.computeFields();
  421.          this.modified = false;
  422.       }
  423.  
  424.    }
  425.  
  426.    private void checkModified() {
  427.       if (this.modified) {
  428.          this.cal.complete();
  429.          this.modified = false;
  430.       }
  431.  
  432.    }
  433. }
  434.